﻿// -------------------------------------------------------------------------
//    @FileName         :    NFGuildCompetitionPart.cpp
//    @Author           :    gaoyi
//    @Date             :    24-8-30
//    @Email            :    445267987@qq.com
//    @Module           :    NFGuildCompetitionPart
//
// -------------------------------------------------------------------------

#include "NFGuildCompetitionPart.h"

#include "proto_city.pb.h"
#include "proto_cs_login.pb.h"
#include "proto_db.pb.h"

NFGuildCompetitionPart::NFGuildCompetitionPart()
{
    if (EN_OBJ_MODE_INIT == NFShmMgr::Instance()->GetCreateMode())
    {
        CreateInit();
    }
    else
    {
        ResumeInit();
    }
}

NFGuildCompetitionPart::~NFGuildCompetitionPart()
{
}

int NFGuildCompetitionPart::CreateInit()
{
    m_bNotify = false;
    return 0;
}

int NFGuildCompetitionPart::ResumeInit()
{
    return 0;
}

int NFGuildCompetitionPart::LoadFromDB(const proto_ff::tbRoleDetail* pDBData)
{
    m_stData.FromPb(pDBData->role_play_data().guild_competition_data());
    return 0;
}

int NFGuildCompetitionPart::InitConfig(proto_ff::tbRoleDetail* pDbData, const RoleOne& stRoleOne)
{
    pDbData->mutable_role_play_data()->mutable_guild_competition_data();
    return 0;
}

int NFGuildCompetitionPart::SaveDB(proto_ff::tbRoleDetail* pDBData)
{
    m_stData.ToPb(pDBData->mutable_role_play_data()->mutable_guild_competition_data());
    return 0;
}

int NFGuildCompetitionPart::MakePlayerDataCS(proto_ff::Proto_CSGetRoleRsp* pCSGetRoleRsp)
{
    m_stData.ToPb(pCSGetRoleRsp->mutable_guild_competition_data());
    return 0;
}

int NFGuildCompetitionPart::MakeCityPlayerData(proto_ff::CityRoleInfo* pGCCityRoleInfo)
{
    CHECK_NULL(0, pGCCityRoleInfo);
    proto_ff::CityRoleGuildCompetitionInfo* pInfo = pGCCityRoleInfo->mutable_guild_competition();
    pInfo->set_camp(GetCamp());
    pInfo->set_battle_uid(GetBattleUID());
    return 0;
}

int NFGuildCompetitionPart::SetBattleID(int iBattleID)
{
    if (m_stData.battle_info.battle_id != iBattleID)
    {
        m_stData.battle_info.battle_id = iBattleID;

        MarkDirty();
    }

    return 0;
}

int NFGuildCompetitionPart::GetBattleID()
{
    return m_stData.battle_info.battle_id;
}

int NFGuildCompetitionPart::SetCamp(proto_ff::enGuildCampType eCamp)
{
    if (m_stData.battle_info.camp != eCamp)
    {
        m_stData.battle_info.camp = (enGuildCampType)eCamp;

        MarkNotify();
    }

    return 0;
}

proto_ff::enGuildCampType NFGuildCompetitionPart::GetCamp()
{
    return (proto_ff::enGuildCampType)m_stData.battle_info.camp;
}

int NFGuildCompetitionPart::SetBattleUID(uint64_t ullBattleUID)
{
    if(m_stData.battle_info.battle_uid != ullBattleUID)
    {
        m_stData.battle_info.battle_uid = ullBattleUID;

        MarkDirty();
    }

    return 0;
}

uint64_t NFGuildCompetitionPart::GetBattleUID()
{
    return m_stData.battle_info.battle_uid;
}

int NFGuildCompetitionPart::MarkNotify(bool bDirty)
{
    m_bNotify = true;

    if (bDirty)
    {
        MarkDirty();
    }

    return 0;
}
